package com.yang.helloworld;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

public class Main {
    public static void main(String[] args) {
        HelloWorld helloWorld1 = new HelloWorld();
        helloWorld1.setName("yang");

        helloWorld1.hello();

//        创建IOC容器的对象
//        ApplicationContext是接口，主要的两个实现类：
//                    1、ClassPathXmlApplicationContext    从类路径下加载配置文件
//                    2、FileSystemXmlApplicationContext   从文件系统中加载配置文件
        //ApplicationContext ioc = new FileSystemXmlApplicationContext("E:\\YXK\\application.xml");
        ApplicationContext ioc = new ClassPathXmlApplicationContext("application.xml");
        //从容器中获取bean
        //利用ID定位到容器中的bean
        HelloWorld helloWorld2 = (HelloWorld) ioc.getBean("hello");

        //Hello.class只能获取单个bean，当有多个时不能使用
        HelloWorld helloWorld3 = ioc.getBean(HelloWorld.class);
        helloWorld3.hello();
        helloWorld2.hello();

        //获取Car
        Car car = (Car) ioc.getBean("car");
        System.out.println(car);


        Car car1 = (Car) ioc.getBean("car1");
        System.out.println(car1);

        System.out.println("-----------------------------------------------------------");

        Person person = (Person) ioc.getBean("person");
        System.out.println(person);

        Person person1 = (Person) ioc.getBean("person1");
        System.out.println(person1);

        Person person2 = (Person) ioc.getBean("person2");
        System.out.println("person2" + person2);


    }
}
